package com.example.common.security.session;

import com.example.common.utils.RequestContextUtil;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;

/**
 * @program: springsecurity-study
 * @description: Session并发控制监听事件
 * @author: ChenZhiXiang
 * @create: 2019-07-30 16:16
 **/
public class ExpiredSessionStrategy implements SessionInformationExpiredStrategy {

    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent sessionInformationExpiredEvent){
        User princaipal = (User) sessionInformationExpiredEvent.getSessionInformation().getPrincipal();
        RequestContextUtil.writeToResponse(princaipal.getUsername()+"在其他地方登录了");
    }
}
